Use GetLocaleInfo() on Windows to get the localized weekday and month
authorTor Lillqvist <tml@novell.com>
Mon, 28 Nov 2005 01:51:08 +0000 (01:51 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Mon, 28 Nov 2005 01:51:08 +0000 (01:51 +0000)
2005-11-28  Tor Lillqvist  <tml@novell.com>

* gtk/gtkcalendar.c (gtk_calendar_init): Use GetLocaleInfo() on
Windows to get the localized weekday and month names. strftime()
in the Microsoft C library returns strings in the default codepage
for the locale of the process, not the system codepage. Thus
g_locale_to_utf8() isn't useable on the return value from
strftime(). (#322603)

ChangeLog
ChangeLog.pre-2-10
gtk/gtkcalendar.c

index 1bd871d9654214b316404f2aa0b9c4c098d363e9..e537933dfdab3c0b6337c40e21bde4ed37270696 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-11-28  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/gtkcalendar.c (gtk_calendar_init): Use GetLocaleInfo() on
+       Windows to get the localized weekday and month names. strftime()
+       in the Microsoft C library returns strings in the default codepage
+       for the locale of the process, not the system codepage. Thus
+       g_locale_to_utf8() isn't useable on the return value from
+       strftime(). (#322603)
+
 2005-11-27  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup): 
index 1bd871d9654214b316404f2aa0b9c4c098d363e9..e537933dfdab3c0b6337c40e21bde4ed37270696 100644 (file)
@@ -1,3 +1,12 @@
+2005-11-28  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/gtkcalendar.c (gtk_calendar_init): Use GetLocaleInfo() on
+       Windows to get the localized weekday and month names. strftime()
+       in the Microsoft C library returns strings in the default codepage
+       for the locale of the process, not the system codepage. Thus
+       g_locale_to_utf8() isn't useable on the return value from
+       strftime(). (#322603)
+
 2005-11-27  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup): 
index 34d76269e1f12f7118bd83d2bff9dc0e6abe5a4f..18cac6fdd42afe3df8717d1f86e455e18c47b5d3 100644 (file)
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
+
+#include <glib.h>
+
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
 #include <glib/gprintf.h>
 
 #undef GTK_DISABLE_DEPRECATED
@@ -562,7 +569,11 @@ gtk_calendar_init (GtkCalendar *calendar)
   struct tm *tm;
   gint i;
   char buffer[255];
+#ifdef G_OS_WIN32
+  wchar_t wbuffer[100];
+#else
   time_t tmp_time;
+#endif
   GtkCalendarPrivate *priv;
   gchar *year_before;
 #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
@@ -583,17 +594,57 @@ gtk_calendar_init (GtkCalendar *calendar)
   if (!default_abbreviated_dayname[0])
     for (i=0; i<7; i++)
       {
+#ifndef G_OS_WIN32
        tmp_time= (i+3)*86400;
        strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
        default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+#else
+       if (G_WIN32_HAVE_WIDECHAR_API ())
+         {
+           if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
+                                wbuffer, G_N_ELEMENTS (wbuffer)))
+             default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
+           else
+             default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+         }
+       else
+         {
+           if (!GetLocaleInfoA (GetThreadLocale (),
+                                (LOCALE_SABBREVDAYNAME1 + (i+6)%7) | LOCALE_USE_CP_ACP,
+                                buffer, G_N_ELEMENTS (buffer)))
+             default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
+           else
+             default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+         }
+#endif
       }
   
   if (!default_monthname[0])
     for (i=0; i<12; i++)
       {
+#ifndef G_OS_WIN32
        tmp_time=i*2764800;
        strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
        default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+#else
+       if (G_WIN32_HAVE_WIDECHAR_API ())
+         {
+           if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
+                                wbuffer, G_N_ELEMENTS (wbuffer)))
+             default_monthname[i] = g_strdup_printf ("(%d)", i);
+           else
+             default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+         }
+       else
+         {
+           if (!GetLocaleInfoA (GetThreadLocale (),
+                                (LOCALE_SMONTHNAME1 + i) | LOCALE_USE_CP_ACP,
+                                buffer, G_N_ELEMENTS (buffer)))
+             default_monthname[i] = g_strdup_printf ("(%d)", i);
+           else
+             default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+         }
+#endif
       }
   
   /* Set defaults */